<?php

namespace IDock\Insurance\ZMBX\Response;

use IDock\Http\Response;
use IDock\Insurance\ZMBX\Response\AllZMBXResponse;
use IDock\Printer\NonCar\NonCarInquirySinglePrinter;
use IDock\Printer\NonCar\NonCarUnderwritingPrinter;
use IDock\Printer\PremiumUnderwritingPrinter;
use IDock\Visitor\NonCar\NonCarProductVisitor;

class UnderwritingResponse extends AllZMBXResponse
{

    /**
     * @var PremiumUnderwritingPrinter $printer
     */
    public $printer = PremiumUnderwritingPrinter::class;

    public function printerInit(): Response
    {
        $data = $this->getBody() ?? [];
        $code = $data['submitStatus'] ?? '';

        $this->printer->inquiryNo = $data['proposalNo'] ?? '';
        $this->printer->ciInquiryNo = $data['forceProposalNo'] ?? '';
        $this->printer->biInquiryNo = $data['bizProposalNo'] ?? '';
        $this->printer->messageTip = $data['submitNotion'] ?? '';

        //非车
        if ($data['accidentNos'] ?? '') {
            $nonCarInquiryPrinter = new NonCarUnderwritingPrinter();

            foreach ($data['accidentNos'] ?? [] as $value) {
                /*** @var $item NonCarProductVisitor */
                $single = new NonCarInquirySinglePrinter();
                $single->inquiryNo = $value['rideProposalNo'] ?? '';
                $single->planCode = $value['rideRiskCode'] ?? '';
                $single->productCode = '';
                $single->statusCode = 'success';
                $nonCarInquiryPrinter->nonCarSingleAppend($single);
            }
            $this->printer->noCarUnderwritingPrinter = $nonCarInquiryPrinter;
        }

        //下发
        if ($code == '2') {
            $this->printer->statusCode = 'U4';
        }
        //成功
        if ($code == '1')  {
            $this->printer->statusCode = 'U1';
        }
        //人工
        if ($code == '3') {
            $this->printer->statusCode = 'U3';
        }
        //拒保
        if ($code == '4') {
            $this->printer->statusCode = 'U6';
        }

        return $this;
    }
}
